package com.tensai.webflux.configurations.swagger;

import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author Tensai
 */
@Configuration
@EnableSwagger2
@EnableOpenApi
@AllArgsConstructor
public class SwaggerConfig {

    private final Swagger2Configurations configurations;

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage(configurations.getBasePackage()))
                .paths(PathSelectors.any())
                .build()
//                .globalRequestParameters(globalRequestParameters)
//                .securitySchemes(securitySchemes()) //添加token
//                .securityContexts(securityContexts()) //swagger配置页面访问是否需要传token
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(configurations.getTitle())
                .description(configurations.getDescription())
                .termsOfServiceUrl(configurations.getTermsOfServiceUrl())
                .version(configurations.getVersion())
                .build();
    }


}
